# 枪练习

class Gun:
    """
    家具类
    """

    def __init__(self, model):
        self.model = model
        self.bullent_count = 0

    def add_bullent(self, count):
        self.bullent_count += count

    def shoot(self):
        # 判断子弹数量

        if self.bullent_count <= 0:
            print("[%s] 没有子弹了。。。" % self.model)
            return

        # 发射子弹
        self.bullent_count -= 1
        # 提示发射信息
        print("[%s] 突突突突突突。。。。[%d]" % (self.model, self.bullent_count))

        pass


class Soldier:
    def __init__(self, name):
        self.name = name
        # 相当于null
        self.gun = None

    def fire(self):
        # 判断士兵是否有枪
        # if self.gun == None:
        if self.gun is None:
            print("士兵[%s]还没有配置枪" % self.name)
            return
        # 喊口号
        print("[%s],冲啊" % self.name)

        # 装填子弹
        self.gun.add_bullent(50)

        # 发射子弹
        self.gun.shoot()
        pass


# 创建枪对象
ak47 = Gun("ak47")
ak47.shoot()

# 创建许三多
soldier = Soldier("许三多")

soldier.gun = ak47
soldier.fire()
